package com.solocredit.finance.ui.user.act

import android.annotation.SuppressLint
import android.app.Activity
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.graphics.Color
import android.os.Build
import android.os.CountDownTimer
import android.text.Editable
import android.text.TextWatcher
import android.view.Gravity
import android.view.View
import android.view.WindowManager
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.GridLayoutManager
import com.google.android.gms.auth.api.phone.SmsRetriever
import com.google.android.gms.common.api.CommonStatusCodes
import com.google.android.gms.common.api.Status
import com.solocredit.finance.R
import com.solocredit.finance.app.MyApp
import com.solocredit.finance.base.utils.DensityUtils
import com.solocredit.finance.base.utils.TitleBarUtil
import com.solocredit.finance.base.utils.helper.ActivityStackManager
import com.solocredit.finance.base.utils.log.MullaLog
import com.solocredit.finance.config.MullaConfigs
import com.solocredit.finance.databinding.ActMullaUserVerificationBinding
import com.solocredit.finance.http.HttpHelper
import com.solocredit.finance.mvp.MvpAct
import com.solocredit.finance.ui.loan.act.MullaLoanDetailsAct
import com.solocredit.finance.ui.user.adapter.MullaUserVerificationTypeAdapter
import com.solocredit.finance.ui.user.impl.MullaVerificationPresenterImpl
import com.solocredit.finance.ui.user.view.IMullaVerificationView
import com.solocredit.finance.utils.decoration.GridSpacingItemDecoration
import com.solocredit.finance.utils.dialog.TipsDialog
import com.solocredit.finance.utils.dialog.VerificationSendSuccessDialog
import com.solocredit.finance.utils.event.MullaEventData
import com.solocredit.finance.utils.event.MullaEventType
import com.solocredit.finance.utils.helper.SharedHelper
import com.solocredit.finance.utils.track.FlexiMolaTracker
import com.solocredit.finance.weight.MullaVerifyEditText
import com.solocredit.finance.weight.input.TimeStampEditText
import com.solocredit.finance.weight.pickerview.builder.TimePickerBuilder
import com.solocredit.finance.weight.pickerview.listener.OnTimeSelectListener
import com.solocredit.finance.weight.pickerview.view.TimePickerView
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.json.JSONObject
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Date

/**
 * FlexiMola
 * @Author wwdeng
 * @CreateTime: 2025/2/13 11:08
 * @Annotation：手机号校验
 */
class MullaUserVerificationAct: MvpAct<IMullaVerificationView,MullaVerificationPresenterImpl>(),IMullaVerificationView{
    private var _binding: ActMullaUserVerificationBinding? = null
    private val binding get() = _binding ?: throw IllegalStateException(
        "Cannot access binding because it is null. Either the view hasn't been created yet, or it has already been destroyed."
    )

    var vTypeAdapter: MullaUserVerificationTypeAdapter? = null

    private var sendSuccessDialog: VerificationSendSuccessDialog? = null
    private var msagBroadcastReceiver: VerificationMSAGBroadcastReceiver? = null
    private val SMS_CONSENT_REQUEST = 200

    //等待时长
    private var countdownTimer: MyCountDownTimer? = null
    private var countdown = 60

    //是否可切换校验类型
    private var isEnabledCheckType = true

    //出生日期选择
    private var pvStartDateView: TimePickerView? = null
    companion object {
        fun start(context: Context) {
            //当前栈顶是 手机号校验页面 不重复跳转
            if (ActivityStackManager.isCurrentActivity(MullaUserVerificationAct::class.java)){
                return
            }
            val intent = Intent(context, MullaUserVerificationAct::class.java)
            context.startActivity(intent)
        }
    }

    override fun getMullaRootView(): View? {
        _binding = ActMullaUserVerificationBinding.inflate(layoutInflater)
        return binding.root
    }

    override fun initMullaView() {
        TitleBarUtil.setStatusBarLightMode(this, false)
        setBackExit(true)
        setMullaTitleBarVisibility(View.VISIBLE)
        setMullaTitleBarColor(Color.parseColor("#FF160807"))
        setMullaBackBtnVisibility(View.INVISIBLE)
        setMullaTextTitleVisibility(View.INVISIBLE)
        setMullaRightBtnRes(R.mipmap.mulla_kefu_icon)
        rootViewBinding.containerLayout.setBackgroundColor(Color.parseColor("#FF160807"))

        initMullaRefreshLayout()
        initFlexiMolaTypeListView()
        showChcekMobileTypeView(false)

        SmsRetriever.getClient(this).startSmsUserConsent(null)
        registerMSAGBroadcastReceiver()
    }

    override fun initMullaListener() {
        //客服
        rootViewBinding.ivFun.setOnClickListener {
            showMullaKefuDialog("Verification Mobile Page")
            HttpHelper.addMullaEventAction(MullaEventType.CLICK.MULLA_CLICK_CUSTOMER, "Verification Mobile Page")
        }
        _binding?.editCode?.addTextChangedListener(object : TextWatcher{
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
            }
            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
            }
            override fun afterTextChanged(s: Editable?) {
                presenter?.let {
                    _binding?.btnContinue?.isEnabled =
                        getMullaCode().isNotEmpty() && it.getCheckNumberSelectType().isNotEmpty()
                }
            }
        })
        _binding?.editCode?.setInputFocusChangeListener(object : TimeStampEditText.IInputFocusChangeListener {
            override fun onFocusChange(v: View?, hasFocus: Boolean) {
                if (hasFocus){
                    _binding?.editCode?.setBackgroundResource(R.drawable.mulla_radius_frame_ff160807_12)
                } else {
                    _binding?.editCode?.setBackgroundResource(R.drawable.mulla_radius_frame_ffe0dbee_12)
                }
            }
            override fun onEditSubmitPointAction(v: View?, remark: String?) {
            }
        })


        _binding?.editMobile?.addTextChangedListener(object : TextWatcher {
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
            }
            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
            }
            override fun afterTextChanged(s: Editable?) {
                _binding?.btnConfirm?.isEnabled = getMullaMobile().isNotEmpty()
            }
        })

        _binding?.btnSend?.setOnClickListener {
            if (presenter.getCheckNumberSelectType().isEmpty() || getMullaMobile().isEmpty()){
                return@setOnClickListener
            }
            presenter?.sendMullaVerificationWhatsAppCodeAction()
        }

        _binding?.imgEdit?.setOnClickListener {
            showChcekMobileTypeView(true)
        }
        _binding?.btnConfirm?.setOnClickListener {
            if (getMullaMobile().isEmpty()){
                return@setOnClickListener
            }
            showChcekMobileTypeView(false)
        }
        //提交
        _binding?.btnContinue?.setOnClickListener {
            HttpHelper.addMullaEventAction(MullaEventType.CLICK.MULLA_CLICK_VERIFICATION_CONTINUE,"${getMullaCode()}##${getMullaMobile()}")
            // TODO: 手机号校验 批量埋点上报
            FlexiMolaTracker.getInstance(MyApp.app).reportImmediately(null)
            if (getMullaMobile().isEmpty() || getMullaCode().isEmpty()){
                _binding?.btnContinue?.isEnabled = false
                return@setOnClickListener
            }
            presenter?.onMullaVerificationCodeAction()
        }
    }

    @SuppressLint("SetTextI18n")
    override fun initMullaData() {
        val zoneCode = SharedHelper.getMullaSPString(SharedHelper.MULLA_SPKEY.MULLA_TIMEZONE_CODE)
        val mobile = SharedHelper.getMullaSPString(SharedHelper.MULLA_SPKEY.MULLA_MOBILE)
        _binding?.textZoneCode?.text = "+$zoneCode"
        _binding?.editMobile?.setText(mobile)

        _binding?.btnSend?.text = getString(R.string.verification_send)
        _binding?.btnSend?.isEnabled = true
        _binding?.btnSend?.setTextColor(Color.parseColor("#FFFFFFFF"))
        _binding?.btnSend?.setBackgroundResource(R.drawable.mulla_circle_fill_ff160807)
        isEnabledCheckType = true

        val dataString = SharedHelper.getMullaSPString(SharedHelper.MULLA_SPKEY.MULLA_PROCESS)
        val obj = JSONObject(dataString)
        val typeList = arrayListOf<JSONObject>()
        if (obj.optString("smsFlag") == "YES"){
            val smsObj = JSONObject()
            smsObj.put("isSelected",true)
            smsObj.put("type","SMS")
            smsObj.put("title",getString(R.string.verification_type_sms))
            typeList.add(smsObj)
            presenter?.setMullaVerificationType("SMS",false)
            _binding?.textType?.text = String.format(getString(R.string.verification_type_hint),smsObj.optString("title"))
        }
        if (obj.optString("whatsappFlag") == "YES"){
            val whatsappObj = JSONObject()
            whatsappObj.put("type","WHATSAPP")
            whatsappObj.put("title",getString(R.string.verification_type_whatsApp))
            typeList.add(whatsappObj)
        }
        vTypeAdapter?.data = typeList

        showVerificationTipsDialog()
    }

    override fun createPresenter(): MullaVerificationPresenterImpl {
        return MullaVerificationPresenterImpl(this)
    }

    /* 初始化刷新 */
    private fun initMullaRefreshLayout() {
        //禁止加载
        _binding?.refreshLayout?.setEnableLoadMore(false)
        _binding?.refreshLayout?.setEnableAutoLoadMore(false)
        _binding?.refreshLayout?.setOnRefreshListener {
            MyApp.app.publisher.publish(MullaEventData(MullaEventData.TYPE.MULLA_PROCESS_REFRESH))
        }
        _binding?.refreshLayout?.setOnLoadMoreListener {
            _binding?.refreshLayout?.finishLoadMore()
        }
    }

    /* 初始化校验类型列表 */
    @SuppressLint("NotifyDataSetChanged")
    private fun initFlexiMolaTypeListView(){
        _binding?.typeListView?.setHasFixedSize(true)
        _binding?.typeListView?.isNestedScrollingEnabled = false
        _binding?.typeListView?.isFocusableInTouchMode = false //不需要焦点
        val leftDecoration = DensityUtils.dp2px(35f)
        _binding?.typeListView?.addItemDecoration(GridSpacingItemDecoration(2, leftDecoration, false))
        val layoutManager = GridLayoutManager(this,2)
        _binding?.typeListView?.layoutManager = layoutManager
        vTypeAdapter = MullaUserVerificationTypeAdapter(_binding?.typeListView)
        _binding?.typeListView?.adapter = vTypeAdapter
        _binding?.typeListView?.itemAnimator = DefaultItemAnimator()
        vTypeAdapter?.setOnItemChildClickListener { _, childView, position ->
            if (childView.id == R.id.itemLayout){
                vTypeAdapter?.let { adapter ->
                    val item = adapter.getItem(position)
                    if (!isEnabledCheckType || item.optBoolean("isSelected")){
                        return@setOnItemChildClickListener
                    }
                    val selectType = item.optString("type")
                    HttpHelper.addMullaEventAction(String.format(MullaEventType.CLICK.MULLA_CLICK_VERIFICATION_TYPE,selectType))
                    adapter.data.forEach { model ->
                        model.put("isSelected",selectType == model.optString("type"))
                        if (selectType == model.optString("type")){
                            presenter?.setMullaVerificationType(selectType,getMullaMobile().isNotEmpty())
                            _binding?.textType?.text = String.format(getString(R.string.verification_type_hint),item.optString("title"))
                        }
                    }
                    adapter.notifyDataSetChanged()
                }
            }
        }
    }

    /**
     * 注册SMS广播接收
     */
    private fun registerMSAGBroadcastReceiver(){
        // 2 register receiver
        val intentFilter = IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION)
        msagBroadcastReceiver = VerificationMSAGBroadcastReceiver {
            startActivityForResult(it, SMS_CONSENT_REQUEST)
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            // Android 13 及以上版本使用 receiverFlags 参数
            registerReceiver(msagBroadcastReceiver, intentFilter, SmsRetriever.SEND_PERMISSION, null, Context.RECEIVER_EXPORTED)// 指定导出标志
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            // Android 8.0 到 Android 12 版本使用带权限的 registerReceiver()
            registerReceiver(msagBroadcastReceiver, intentFilter, SmsRetriever.SEND_PERMISSION, null)
        } else {
            // Android 8.0 以下版本，只使用 receiver 和 intentFilter 参数
            registerReceiver(msagBroadcastReceiver, intentFilter)
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == SMS_CONSENT_REQUEST) {
            if (resultCode == Activity.RESULT_OK && data != null) {
                // 读取短信内容
                val message = data.getStringExtra(SmsRetriever.EXTRA_SMS_MESSAGE)
                MullaLog.e("Sms content: $message")

                // 提取otp
                val code = extractFirstNumber(message)
                MullaLog.e("Sms code: $code")
                if (code != null){
                    _binding?.editCode?.setText(code)
                }
            } else {
                // 用户不同意或没收到待
                MullaLog.e("User canceled or no message received")
            }
        }
    }

    /**
     * 提取连续的数字
     */
    private fun extractFirstNumber(input: String?): String? {
        if(input.isNullOrBlank()) return ""

        val regex = "\\d+".toRegex()
        return regex.find(input)?.value
    }

    override fun getMullaMobile(): String {
        _binding?.let {
            return it.editMobile.text.toString()
        }
        return ""
    }

    override fun getMullaCode(): String {
        _binding?.editCode?.let {
            return it.text.toString()
        }
        return ""
    }

    /**
     * 发送成功提示
     */
    private fun showSendCodeSuccessDialog(){
        if (sendSuccessDialog == null){
            sendSuccessDialog = VerificationSendSuccessDialog(this)
            sendSuccessDialog?.setCancelable(true)
            sendSuccessDialog?.setCanceledOnTouchOutside(false)
        }
        sendSuccessDialog?.show()
        sendSuccessDialog?.showMullaSuccessTips(getString(R.string.verification_send_success_tips))
        launch(Dispatchers.Main){
            delay(1500)
            if (!isFinishing && sendSuccessDialog?.isShowing == true) {
                sendSuccessDialog?.dismiss()
            }
            _binding?.let {
                //发送验证码成功，验证码输入框获得焦点
                onShowSoftInput(it.editCode)
            }
        }
    }

    /**
     * 提示dialog
     */
    private fun showVerificationTipsDialog(){
        val tipsDialog = TipsDialog(this,"Verification Mobile Page",object : TipsDialog.IDialogCallback{
            override fun onClick(view: View?) {
            }
        })
        tipsDialog.show()
        tipsDialog.setTips(getString(R.string.verification_dialog_tips))
        tipsDialog.setBtnText(getString(R.string.verification_dialog_know))
    }

    /**
     * 切换是否修改手机号View
     */
    private fun showChcekMobileTypeView(isEdit: Boolean){
        val dataString = SharedHelper.getMullaSPString(SharedHelper.MULLA_SPKEY.MULLA_PROCESS)
        val obj = JSONObject(dataString)
        //是否允许修改手机号码
        if (obj.optString("mobileEditFlag") == "NO"){
            _binding?.editMobile?.isEnabled = false
            _binding?.imgEdit?.visibility = View.INVISIBLE
            _binding?.btnConfirm?.visibility = View.GONE
            _binding?.vEditMobileLine?.visibility = View.INVISIBLE
            return
        }
        when(isEdit){
            true -> {
                _binding?.editMobile?.isEnabled = true
                _binding?.let {
                    onShowSoftInput(it.editMobile)
                }
                _binding?.editMobile?.setSelection(getMullaMobile().length)
                _binding?.imgEdit?.visibility = View.INVISIBLE
                _binding?.btnConfirm?.visibility = View.VISIBLE
                _binding?.vEditMobileLine?.visibility = View.VISIBLE
            }
            else -> {
                _binding?.editMobile?.isEnabled = false
                _binding?.imgEdit?.visibility = View.VISIBLE
                _binding?.btnConfirm?.visibility = View.GONE
                _binding?.vEditMobileLine?.visibility = View.INVISIBLE
            }
        }
    }

    override fun showMullaVerificationType(type: String) {
        _binding?.btnContinue?.isEnabled = getMullaCode().isNotEmpty()
    }

    override fun showMullaSendCodeSuccess(directLoginFlag: String) {
        hideMullaLoading()
        when(directLoginFlag){
            "YES" -> {
                showMullaVerificationSuccess()
            }
            else -> {
                startCountdownTimer()
            }
        }
    }

    /**
     * 选择出生日期
     */
    var startTime = 0L
    override fun showMullaChooseBirthdayDialog() {
        //开始选择时间
        startTime = System.currentTimeMillis()
        if(pvStartDateView == null){
            //时间可选范围18-100岁
            //当前日期
            val curtDate = Calendar.getInstance()
            val startDate = Calendar.getInstance()
            startDate.timeInMillis = curtDate.timeInMillis
            startDate.add(Calendar.YEAR,-100)

            val endDate = Calendar.getInstance()
            endDate.timeInMillis = curtDate.timeInMillis
            endDate.add(Calendar.YEAR,-18)

            pvStartDateView = TimePickerBuilder(this, object : OnTimeSelectListener {
                override fun onTimeSelect(date: Date?, v: View?) {
                }

                @SuppressLint("SimpleDateFormat")
                override fun onTimeSelectString(date: Date?, showDate: String?) {
                    date?.let {
                        val value = SimpleDateFormat("yyyy-MM-dd").format(it)
                        presenter?.onMullaVerificationCodeAction(value)
                    }
                }
            })
                .setDate(endDate) //默认选中
                .setRangDate(startDate, endDate) //可选择时间范围
                .setLayoutRes(R.layout.dialog_mulla_birthday) { v ->
                    val ivClose = v.findViewById<ImageView>(R.id.ivClose)
                    ivClose.setOnClickListener {
                        pvStartDateView?.dismiss()
                    }
                    //确定
                    val btnDone = v.findViewById<TextView>(R.id.btnDone)
                    btnDone.setOnClickListener {
                        pvStartDateView?.returnData()
                        pvStartDateView?.dismiss()
                    }
                }
                .isDialog(true)
                .setContentTextSize(16)
                .setType(booleanArrayOf(true, true, true, false, false, false))
                .setLabel("", "", "", "", "", "")
                .setLineSpacingMultiplier(3f)
                .setTextXOffset(40, 40, 40, 40, 40, 40)
                .isCenterLabel(false)//是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .setTextColorCenter(Color.parseColor("#FF08252C")) //设置选中项文字颜色
                .setTextColorOut(Color.parseColor("#FF9CA8AB"))//默认颜色
                .setBgColor(Color.parseColor("#00000000"))
                .isAlphaGradient(true)
                .setItemVisibleCount(5)
                .isCyclic(true)
                .setDividerColor(ContextCompat.getColor(this, R.color.transparent))
                .build()
            val dialog = pvStartDateView?.dialog
            if (dialog != null){
                val dialogWindow = dialog.window
                if (dialogWindow != null) {
                    val params = dialogWindow.attributes
                    params.width = WindowManager.LayoutParams.MATCH_PARENT
                    params.height = WindowManager.LayoutParams.WRAP_CONTENT
                    dialogWindow.attributes = params
                    dialogWindow.setWindowAnimations(R.style.picker_view_slide_anim) //修改动画样式
                    dialogWindow.setGravity(Gravity.BOTTOM)
                    dialogWindow.setDimAmount(0.3f)
                }
            }
        }
        pvStartDateView?.show()
    }

    override fun showMullaVerificationSuccess() {
        SharedHelper.saveMullaSPData(SharedHelper.MULLA_SPKEY.MULLA_MOBILE, getMullaMobile())
        MyApp.app.publisher.publish(MullaEventData(MullaEventData.TYPE.MULLA_PROCESS_REFRESH))
        if (countdownTimer != null){
            countdownTimer?.cancel()
        }

        val pName = MullaConfigs.clickProductName
        val pToken = MullaConfigs.clickProductToken
        //产品名和Token不为空，说明是申贷后进入的校验，需要进入贷款详情
        if (pName.isNotEmpty() && pToken.isNotEmpty()){
            val pLogo = MullaConfigs.clickProductLogo
            val pTitle = MullaConfigs.clickProductTitle
            MullaLoanDetailsAct.start(this, pLogo, pName, pToken,pTitle)
        }
        finish()
    }

    class MyCountDownTimer(private val act: MullaUserVerificationAct, millisInFuture: Int, countDownInterval: Long): CountDownTimer(millisInFuture.toLong(), countDownInterval) {
        override fun onTick(millisUntilFinished: Long) {
            // 这里每隔一段时间（定时器间隔）会被调用
            // 可以在这里更新UI，显示剩余时间
            act.countdown = (millisUntilFinished / 1000).toInt()
            act.showCheckCountdownText()
        }
        override fun onFinish() {
            // 倒计时完成时被调用
            act.showCheckCountdownComplete()
        }
    }

    /**
     * 倒计时
     */
    @SuppressLint("SetTextI18n")
    private fun showCheckCountdownText(){
        _binding?.btnSend?.text = "$countdown S"
    }

    /**
     * 倒计时完成
     */
    private fun showCheckCountdownComplete(){
        countdown = 60
        _binding?.btnSend?.text = getString(R.string.verification_send)
        _binding?.btnSend?.isEnabled = true
        _binding?.btnSend?.setTextColor(Color.parseColor("#FFFFFFFF"))
        _binding?.btnSend?.setBackgroundResource(R.drawable.mulla_circle_fill_ff160807)
        isEnabledCheckType = true

        showChcekMobileTypeView(false)
    }

    /**
     * 自动获取短信验证码广播
     */
    class VerificationMSAGBroadcastReceiver(val result: (Intent) -> Unit): BroadcastReceiver() {
        override fun onReceive(context: Context?, intent: Intent) {
            if (SmsRetriever.SMS_RETRIEVED_ACTION == intent.action) {
                val extras = intent.extras
                val status: Status? = extras?.get(SmsRetriever.EXTRA_STATUS) as? Status
                val code = status?.statusCode ?: -1
                if (code == CommonStatusCodes.SUCCESS) {
                    //获取内容Intent，只能通过 startActivityForResult(intent) 才能读取短信内容
                    val consentIntent = extras?.getParcelable<Intent>(SmsRetriever.EXTRA_CONSENT_INTENT)
                    consentIntent?.let {
                        result.invoke(it)
                    }
                }
            }
        }
    }

    /**
     * 启动倒计时
     */
    @SuppressLint("SetTextI18n")
    private fun startCountdownTimer() {
        showSendCodeSuccessDialog()
        //随机 60秒 等待时长
        countdown = 60
        _binding?.btnSend?.text = "$countdown S"
        _binding?.btnSend?.isEnabled = false
        _binding?.btnSend?.setTextColor(Color.parseColor("#FF869591"))
        _binding?.btnSend?.setBackgroundResource(R.drawable.mulla_circle_fill_ffe1e1e1)
        isEnabledCheckType = false
        //手机号码输入框变成不可编辑状态
        _binding?.editMobile?.isEnabled = false
        _binding?.vEditMobileLine?.visibility = View.INVISIBLE
        _binding?.imgEdit?.visibility = View.INVISIBLE
        _binding?.btnConfirm?.visibility = View.GONE

        if (countdownTimer == null){
            countdownTimer = MyCountDownTimer(this, countdown * 1000, 1000)
        }
        countdownTimer?.start()
    }

    override fun onMullaEvent(event: MullaEventData) {
        super.onMullaEvent(event)
        when(event.eventType){
            MullaEventData.TYPE.MULLA_PROCESS_REFRESHED -> {
                hideMullaLoading()
                //需要校验 WhatsApp 或 SMS
                val dataString = SharedHelper.getMullaSPString(SharedHelper.MULLA_SPKEY.MULLA_PROCESS)
                val obj = JSONObject(dataString)
                if (obj.optString("smsFlag") != "YES" && obj.optString("whatsappFlag") != "YES"){
                    //校验成功
                    showMullaVerificationSuccess()
                }
            }
            else -> {

            }
        }
    }

    override fun hideMullaLoading() {
        super.hideMullaLoading()
        _binding?.refreshLayout?.finishRefresh()
    }

    override fun onStart() {
        super.onStart()
        HttpHelper.addMullaEventAction(MullaEventType.PAGE.MULLA_PAGE_VERIFICATION_MOBILE_START)
    }

    override fun onDestroy() {
        super.onDestroy()
        HttpHelper.addMullaEventAction(MullaEventType.PAGE.MULLA_PAGE_VERIFICATION_MOBILE_END)
        if (countdownTimer != null){
            countdownTimer?.cancel()
            countdownTimer = null
        }
        if (msagBroadcastReceiver != null){
            unregisterReceiver(msagBroadcastReceiver)
        }
        _binding = null
    }
}